﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json.Linq;
using System.Web.Script.Serialization;
using System.IO;

namespace WebBHXH.Entities
{
    public class MaDotBHModel
    {

        public MaDotBHModel()
        { }
        public MaDotBHModel(string json)
        {
            JObject jObject = JObject.Parse(json);
            maDotBH = (string)jObject["Ma_DotBH"];
            donViBH = (string)jObject["Ma_DonViBH"];
            maTinh = (string)jObject["Ma_Tinh"];
            huyen = (string)jObject["Ma_Huyen"];
            doiTuong = (string)jObject["DoiTuong"];
            ngayLap = (DateTime)jObject["NgayLap"];
            loaiBH = (string)jObject["Ma_LoaiBH"];
            mucBH = (string)jObject["Ma_MucBH"];
            soTien1Nam = (int)jObject["SoTien1Nam"];
            nguoiSudung = (string)jObject["Ma_NSD"];
            ngayTaoMoi = (DateTime)jObject["NgayTaoMoi"];
            //ngayCapNhat = (DateTime)jObject["NgayCapNhat"];
            ngayCapNhat = new DateTime();
        }

        public MaDotBHModel GetDotBHById(string id)
        { 
            System.Net.WebRequest request = System.Net.WebRequest.Create(""+Util.getUrl() + "Home/GetDotBHById?id=" + id);

            request.Method = "POST";
            request.ContentLength = 0;
            request.ContentType = "application/json; charset=utf-8";
            JavaScriptSerializer json_serializer = new JavaScriptSerializer();
            //get response-stream, and use a streamReader to read the content

            using (Stream s = request.GetResponse().GetResponseStream())
            {
                using (StreamReader sr = new StreamReader(s))
                {
                    JavaScriptSerializer jsonserializer = new JavaScriptSerializer();
                    MaDotBHModel maDotBHModel = jsonserializer.Deserialize<MaDotBHModel>(sr.ReadToEnd());
                    return maDotBHModel;
                }
            }

            return new MaDotBHModel();
        }

        public List<MaDotBHModel> GetDotBH()
        {
            System.Net.WebRequest request = System.Net.WebRequest.Create("" + Util.getUrl() + "Home/GetMaDotBHModel");

            request.Method = "POST";
            request.ContentLength = 0;
            request.ContentType = "application/json; charset=utf-8";
            JavaScriptSerializer json_serializer = new JavaScriptSerializer();
            //get response-stream, and use a streamReader to read the content
            List<MaDotBHModel> listMaDotBHModel = new List<MaDotBHModel>();
            using (Stream s = request.GetResponse().GetResponseStream())
            {
                using (StreamReader sr = new StreamReader(s))
                {
                    JavaScriptSerializer jsonserializer = new JavaScriptSerializer();
                    listMaDotBHModel = jsonserializer.Deserialize<List<MaDotBHModel>>(sr.ReadToEnd());
                    return listMaDotBHModel;
                }
            }

            return new List<MaDotBHModel>();
        }

        private string maDotBH;

        public string MaDotBH
        {
            get { return maDotBH; }
            set { maDotBH = value; }
        }
        private string donViBH;

        public string DonViBH
        {
            get { return donViBH; }
            set { donViBH = value; }
        }
        private string maTinh;

        public string MaTinh
        {
            get { return maTinh; }
            set { maTinh = value; }
        }
        private string huyen;

        public string Huyen
        {
            get { return huyen; }
            set { huyen = value; }
        }
        private string doiTuong;

        public string DoiTuong
        {
            get { return doiTuong; }
            set { doiTuong = value; }
        }
        private DateTime ngayLap;

        public DateTime NgayLap
        {
            get { return ngayLap; }
            set { ngayLap = value; }
        }
        private string loaiBH;

        public string LoaiBH
        {
            get { return loaiBH; }
            set { loaiBH = value; }
        }
        private string mucBH;

        public string MucBH
        {
            get { return mucBH; }
            set { mucBH = value; }
        }
        private int soTien1Nam;

        public int SoTien1Nam
        {
            get { return soTien1Nam; }
            set { soTien1Nam = value; }
        }
        private string nguoiSudung;

        public string NguoiSudung
        {
            get { return nguoiSudung; }
            set { nguoiSudung = value; }
        }
        private DateTime ngayTaoMoi;

        public DateTime NgayTaoMoi
        {
            get { return ngayTaoMoi; }
            set { ngayTaoMoi = value; }
        }
        private DateTime ngayCapNhat;

        public DateTime NgayCapNhat
        {
            get { return ngayCapNhat; }
            set { ngayCapNhat = value; }
        }

    }
}